/*
 * Copyright (c) 2006, 2021, webrx.cn All rights reserved.
 *
 */
package cn.webrx.config;

import com.zaxxer.hikari.HikariDataSource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
import org.springframework.core.env.Environment;

import javax.sql.DataSource;

/**
 * <p>Project: mybatis2021 - HiKariCPConfig
 * <p>Powered by webrx On 2021-07-19 14:35:55
 * <p>Created by IntelliJ IDEA
 *
 * @author webrx [webrx@126.com]
 * @version 1.0
 * @since 15
 */
@Configuration
@PropertySource("classpath:db.properties")
public class HiKariCPConfig {
    @Autowired
    private Environment env;

    @Value("${db.driver}")
    private String driver;

    @Bean("ds")
    public DataSource dateSource(@Value("${db.url}") String url) {
        HikariDataSource ds = new HikariDataSource();
        ds.setUsername(env.getProperty("db.username"));
        ds.setJdbcUrl(url);
        ds.setPassword(env.getProperty("db.password"));
        ds.setDriverClassName(driver);
        return ds;
    }


}
